﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class WebUserControl_Khaibaoungvienhoanthanhkhoahuanluyen : System.Web.UI.UserControl
{
   
    ClassExecute.ClassExecute dt;
    string str = BCDataCenter.Configuration.CurrentConnectionString;
    static string error = "";
    protected void Page_Load(object sender, EventArgs e)       
    {
        if (!IsPostBack)
        {
            Txt_ngay.Text = DateTime.Now.ToString("dd/MM/yyyy");
            BindKhoaHL();
        }
       
    }
    void BindKhoaHL()
    {
        dt=new ClassExecute.ClassExecute();
        DataTable db=dt.Get_Data_DataTable(str,ref error,"Get_TrainCourse",CommandType.StoredProcedure);
        Drl_khoahuanluyen.DataSource = db;
        Drl_khoahuanluyen.DataValueField = "CourseID";
        Drl_khoahuanluyen.DataTextField = "CourseDesc";
        Drl_khoahuanluyen.DataBind();
    }
    private void getARSale(string salesp_key)
    {

        dt = new ClassExecute.ClassExecute();
        try
        {
            DataTable db = dt.Get_Data_DataTable(str, ref error, "ls_getBA4PassTraining", CommandType.StoredProcedure,
                new SqlParameter("@salesPKey", salesp_key),
                new SqlParameter("@courseID", Drl_khoahuanluyen.SelectedValue.ToString()));
            if (db.Rows.Count > 0)
            {
                gv_tuvanvien.DataSource = db;
                gv_tuvanvien.DataBind();
            }
            else
            {
                uscMsgBox1.AddMessage("BA không tồn tại hoặc đã học khóa huấn luyện này rồi" +error, uscMsgBox.enmMessageType.Error);

            }
        }
        catch (Exception ex)
        {
            BCDataCenter.ClassWriteLogErr obj = new BCDataCenter.ClassWriteLogErr();
            string method = System.Reflection.MethodBase.GetCurrentMethod().Name;
            obj.ErrorLog(ex.Message, method);
        }
     
    }
    private void insertHRPastTrain(string courseID,string teacher,string traindate,string morenote,string users)
    {
        dt = new ClassExecute.ClassExecute();
        bool kq = false;
        for (int i = 0; i < gv_tuvanvien.Rows.Count; i++)
        {
            GridViewRow row = gv_tuvanvien.Rows[i];
            bool ischecked = ((CheckBox)row.FindControl("checkbox1")).Checked;
            if (ischecked)
            {
               
                string salespkey = gv_tuvanvien.Rows[i].Cells[1].Text.ToString();
                kq = dt.ExecuteSQl_bool(str,CommandType.StoredProcedure,"Insert_HRpasttrain",ref error,
                    new SqlParameter("@course_ID", courseID),
                    new SqlParameter("@salespkey", salespkey),
                    new SqlParameter("@teacher", teacher),
                    new SqlParameter("@trainingdate",traindate),
                    new SqlParameter("@morenote",morenote),
                    new SqlParameter("@users",users));
               
            }
        }
       
        if (kq)
        {
            uscMsgBox1.AddMessage("Hoàn thành cập nhật", uscMsgBox.enmMessageType.Success);
        }
        else
        {
            uscMsgBox1.AddMessage(error, uscMsgBox.enmMessageType.Error);
        }
    }
    protected void bt_luu_Click(object sender, EventArgs e)
    {
        insertHRPastTrain(Drl_khoahuanluyen.SelectedValue.ToString(),txt_Nguoihuanluyen.Text,Txt_ngay.Text,"0",Session["username"].ToString());
    }
    protected void btChon_Click(object sender, EventArgs e)
    {
        getARSale(txtBA.Text);
    }
}
